#include "thingy.h"
#include <QtGui>
#include <QSpinBox>
#include <QLabel>

Thingy::Thingy(QWidget *parent, Being *item, int t) :
    QDialog(parent), item(item)
{
    QLabel *lSpeed = new QLabel(tr("Czas ruchu:"));
    QLabel *lWeight = new QLabel(tr("Wielkosc aktualna:"));
    QLabel *lMinW = new QLabel(tr("Wielkosc minimalna:"));
    QLabel *lMaxW = new QLabel(tr("Wielkosc rozrodcza:"));
    QGridLayout *mainLayout = new QGridLayout;
    speed = new QSpinBox(this);
    speed->setMaximum(4000);
    speed->setMinimum(200);
    minW = new QSpinBox(this);
    minW->setMinimum(1);
    minW->setMaximum(30000);
    weight = new QSpinBox(this);
    weight->setMinimum(1);
    weight->setMaximum(30000);
    spawnW = new QSpinBox(this);
    spawnW->setMinimum(1);
    spawnW->setMaximum(30000);

    if (t == 1)
    {
        rm = new QPushButton("&Usuń");
        mainLayout->addWidget(rm,4,1);
        ok = new QPushButton("&OK");
        mainLayout->addWidget(ok,4,3);
        connect(ok,SIGNAL(clicked()),this,SLOT(dodaj()));
        setWindowTitle(tr("Parametry stworzenia"));
        connect(rm,SIGNAL(clicked()),this,SLOT(usun()));
        speed->setValue(item->speed);
        spawnW->setValue(item->spawnW);
        minW->setValue(item->minW);
        weight->setValue(item->weight);
        cancel = new QPushButton("&Anuluj");
        connect(cancel,SIGNAL(clicked()),this,SLOT(anuluj()));
    }
    else if (t == 0)
    {
        ok = new QPushButton("&Dodaj");
        mainLayout->addWidget(ok,4,1);
        setWindowTitle(tr("Nowe stworzenie"));
        connect(ok,SIGNAL(clicked()),this,SLOT(dodaj()));
        speed->setValue(500);
        spawnW->setValue(6000);
        minW->setValue(1000);
        weight->setValue(3000);
        cancel = new QPushButton("&Anuluj");
        connect(cancel,SIGNAL(clicked()),this,SLOT(anuluj()));
    }
    else if (t == -1)
    {
        setWindowTitle(tr("Parametry stworzenia"));
        speed->setValue(item->speed);
        speed->setReadOnly(true);
        spawnW->setValue(item->spawnW);
        spawnW->setReadOnly(true);
        minW->setValue(item->minW);
        minW->setReadOnly(true);
        weight->setValue(item->weight);
        weight->setReadOnly(true);
        cancel = new QPushButton("&OK");
        connect(cancel,SIGNAL(clicked()),this,SLOT(anuluj()));
    }


    mainLayout->addWidget(lSpeed, 0, 0);
    mainLayout->addWidget(speed, 0, 1);
    mainLayout->addWidget(lWeight, 1, 0);
    mainLayout->addWidget(weight, 1, 1);
    mainLayout->addWidget(lMinW, 2, 0);
    mainLayout->addWidget(minW, 2, 1);
    mainLayout->addWidget(lMaxW, 3, 0);
    mainLayout->addWidget(spawnW, 3, 1);
    mainLayout->addWidget(cancel, 4, 0);
    setLayout(mainLayout);


    setAttribute(Qt::WA_DeleteOnClose);
}

void Thingy::dodaj()
{
    item->speed = speed->value();
    item->typeOf = 0;
    item->minW = minW->value();
    item->weight = weight->value();
    item->spawnW = spawnW->value();
    done(1);
}

void Thingy::anuluj()
{
    done(0);
}

void Thingy::usun()
{
    done(-1);
}
